﻿@{
    Layout = "_LayoutH";
    @model Wms_material
}
<div id="app" v-cloak>
    <h1 style="text-align:center">@ViewBag.SourceName</h1>
    <div class="form">
        <table id="table" class="table table-bordered">
            <thead>
                <tr>
                    <th>物料名称</th>
                    <th>排序</th>
                </tr>
            </thead>
            <tbody>
                @{
                    var matList = ViewBag.matList as List<Wms_material>;

                    @foreach (var item in matList)
                    {
                        <tr name="@item.MaterialId">
                            <td>@item.MaterialName</td>
                            <td>
                                @*<button type="button" class="btn btn-danger" onclick="moveUp(this)">上移</button>
                                    <button type="button" class="btn-info" onclick="moveDown(this)">下移</button>*@
                                <a href="javascript:void(0)" style="cursor:pointer" onclick="moveUp(this)">上移</a>
                                <a href="javascript:void(0)" style="cursor:pointer" onclick="moveDown(this)">下移</a>
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>
        <div class="box-footer">
            <div class="pull-right box-tools">
                <button class="btn btn-success" onclick="orderSubmit()">提交</button>
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript">
        @*var app = new Vue({
            el: "#app",
            data: {
                source:@ViewBag.Source
            },
            computed: {
                count: function () {
                    return this.strLength(this.Remark, false);
                }
            },
            methods: {
                loadL: function (id, type) {
                    var _self = this;
                    if (type === 1) {
                        yui.$axiosget('/StorageRack/GetReservoirarea2?id=' + id).then(function (response) {
                            _self.rlist = response.data;
                        });
                    } else {
                        yui.$axiosget('/StorageRack/GetStoragerack?id=' + id).then(function (response) {
                            _self.slist = response.data;
                        });
                    }
                },
                addL: function () {
                    var _self = this;
                    if (_self.MaterialName.length <= 0) {
                        layer.msg("物料名称不能为空", { icon: 2 });
                        return false;
                    }

                    if (_self.Unit.length <= 0) {
                        layer.msg("请输入单位", { icon: 2 });
                        return false;
                    }
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });
                    var data = {
                        id: _self.MaterialId,
                        MaterialName: _self.MaterialName,
                        Unit: _self.Unit,
                        Remark: _self.Remark
                    };
                    yui.$axiospostform('/Material/AddOrUpdate', data)
                        .then(function (response) {
                            if (response.data.Item1 === 101) {
                                layer.tips(response.data.Item2, '.layui-layer-setwin', {
                                    tips: [1, '#3595CC'],
                                    time: 3000
                                });
                                layer.close(index);
                                return false;
                            }
                            if (response.data.Item1) {
                                layer.msg(response.data.Item2, { icon: 1, time: 1000 });
                                setTimeout(function () {
                                    yui.layer_close3();
                                }, 500);
                            } else {
                                layer.msg(response.data.Item2 || errorMsg, { icon: 5 });
                            }
                            layer.close(index);
                        })
                        .catch(function (error) {
                            layer.close(index);
                        });
                }
            }
        });*@

        function moveDown(_a) {
            //通过链接对象获取表格行的引用
            var _row = $(_a).parent().parent();
            var _nextRow = _row.next();
            //如果不是最后一行，则与下一行交换顺序
            if (_nextRow.length > 0) swapNode(_row, _nextRow.first());
            return false;
        }
        function moveUp(_a) {
            //通过链接对象获取表格行的引用
            var _row = $(_a).parent().parent();
            var _prevRow = _row.prev();
            //如果不是最后一行，则与下一行交换顺序
            if (_prevRow.length > 0) swapNode(_prevRow.first(), _row);
            return false;
        }
        //定义通用的函数交换两个结点的位置
        function swapNode(node1, node2) {
            node2.after(node1);
        }

        function orderSubmit() {
            var matList = [];
            $("#table").find("tbody").find("tr").each(function (i) {
                var matId = $(this).attr("name");
                matList[i] = matId;
            });
            console.log(matList);

            var data = {};
            data.matIdList = matList;
            data.source=@ViewBag.Source;

            yui.$axiospostform('/Material/OrderOper', data)
                .then(function (response) {
                    if (response.data > 0) {
                        alert("成功！")
                    } else {
                        alert("失败！");
                    }
                })
                .catch(function (error) {
                    layer.msg(error.message, { icon: 5 });
                });
        }
    </script>
}